package org.example.writable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReduce extends Reducer<Text, FlowBean, Text, FlowBean> {
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Reducer<Text, FlowBean, Text, FlowBean>.Context context) throws IOException, InterruptedException {
        long totalUp = 0;
        long totalDown = 0;
        for (FlowBean value : values) {
            totalUp = value.getUpFlow();
            totalDown = value.getDownFlow();
        }

        FlowBean flowBean = new FlowBean();
        flowBean.setUpFlow(totalUp);
        flowBean.setDownFlow(totalDown);
        flowBean.setSumFlow();

        context.write(key, flowBean);
    }
}

